﻿//"use strict";

//Array Literal notation
//var studentArray = [];
var studentArray = new Array();

//Object literal notation
var student1 = {
    firstName: 'Nick',
    lastName: 'Brittain',
    gradeLevel: 'Freshmen'
};

//Push student1 on to the studentArray
studentArray.push(student1);

var student2 = {
    firstName: 'Coral',
    lastName: 'Morris',
    gradeLevel: 'Sophomore'
};

studentArray.push(student2);

var displayTable = function () {
    //Get a reference to the DIV tag with ID 'result'
    var resultDiv = document.getElementById('result');

    var h = '<table>';
    h += '<tr>';
    h += '<th>First Name</th>';
    h += '<th>Last Name</th>';
    h += '<th>Grade Level</th>';
    h += '</tr>';

    for (var i = 0; i < studentArray.length; i++) {
        h += '<tr>';
        h += '<td>' + studentArray[i].firstName + '</td>';
        h += '<td>' + studentArray[i].lastName + '</td>';
        h += '<td>' + studentArray[i].gradeLevel + '</td>';
        h += '</tr>';
    }

    h += '</table>';

    //Finally, add the string of html that is in the h variable to the result DIV tag
    resultDiv.innerHTML = h;
}

displayTable();

var result = {};
result.value = 15;

var addNumbers = function (result) {
    //var result = 0;

    for (var i = 0; i < arguments.length; i++) {
        if (typeof (arguments[i]) == 'number') {
            result.value += arguments[i];
        }
    }

    //return result;
}

addNumbers(result, 3, 'nick', 8);
//alert(result);


var addStudent = function () {
    var firstNameInput = document.getElementById('firstName');
    var lastNameInput = document.getElementById('lastName');
    var gradeLevelInput = document.getElementById('gradeLevel');
    
    var s = {
        firstName: firstNameInput.value,
        lastName: lastNameInput.value,
        gradeLevel: gradeLevelInput.value
    };

    studentArray.push(s);

    firstNameInput.value = '';
    lastNameInput.value = '';
    gradeLevelInput.value = '';

    displayTable();
}